﻿using AutoMapper;
using Domain.Entity;
using Domain.Entity.bs;
using Domain.Entity.sys;
using Domain.Entity.zct;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Application.SupplierService
{
    public class SupplierService : ISupplierService
    {
        private readonly ISupplierRepository supplierRepository;
        private readonly IMapper mapper;

        public SupplierService(ISupplierRepository supplierRepository, IMapper mapper)
        {
            this.supplierRepository = supplierRepository;
            this.mapper = mapper;
        }

        public Task<int> AddSupplier(AddSupplierDto addSupplierDto)
        {
            Supplier supplier = mapper.Map<Supplier>(addSupplierDto);
            return supplierRepository.AddSupplier(supplier);
        }

        public Task<int> DeleteSupplier(int id)
        {
            return supplierRepository.DeleteSupplier(id);
        }

        public Task<int> UpdateSupplier(UpdateSupplierDto updateSupplierDto)
        {
            Supplier supplier = mapper.Map<Supplier>(updateSupplierDto);
            return supplierRepository.UpdateSupplier(supplier);
        }

        public Task<FenYe<Supplier>> GetSupplier(FenYe<Supplier> fenYe, string? sup_code, string? sup_name, int? sup_status, string? sup_industry, string? sup_userName)
        {
            return supplierRepository.GetSupplier(fenYe,sup_code, sup_name, sup_status, sup_industry, sup_userName);
        }

        public Task<List<Department>> GetDepartment(int? Department_id)
        {
            return supplierRepository.GetDepartment(Department_id);
        }

        public Task<List<User>> GetUser(int? Department_id)
        {
            return supplierRepository.GetUser(Department_id);
        }

        public Task<List<DictData>> GetDictData(int dict_id)
        {
            return supplierRepository.GetDictData(dict_id);
        }

        public Task<Supplier> GetIdSupplier(int id)
        {
            return supplierRepository.GetIdSupplier(id);
        }

        public Task<FenYe<Supplier>> GetSeniorSupplier(FenYe<Supplier> fenYe, string? sup_code, string? sup_name, string? sup_industry, string? sup_type, string? sup_linkman, string? sup_linkphone, string? sup_email, string? sup_depName, string? sup_userName, int? sup_status, string? sup_address, string? sup_accountName, string? sup_taxpayerNum, string? sup_bankAccount, string? sup_openBank, string? create_name, string? startTime, string? endTime)
        {
                return supplierRepository.GetSeniorSupplier(fenYe, sup_code, sup_name, sup_industry, sup_type, sup_linkman, sup_linkphone, sup_email, sup_depName, sup_userName, sup_status, sup_address, sup_accountName, sup_taxpayerNum, sup_bankAccount, sup_openBank, create_name, startTime, endTime);
        }

        /// <summary>
        /// 查询所有供应商编号
        /// </summary>
        public Task<List<string>> GetSupplierID()
        {
            return supplierRepository.GetSupplierID();
        }

        //查询所有供应商
        public async Task<List<Supplier>> GetAllSupplier()
        {
            return await supplierRepository.GetAllSupplier();
        }

        //修改状态
        public async Task<int> UpdateStatus(int id, int sup_status)
        {
            return await supplierRepository.UpdateStatus(id,sup_status);
        }
    }
}
